import Router from './router';
import store from './store';
import { Message } from 'element-ui';

Router.beforeEach((to, from, next) => {
  if (store.getters.token) {
    if (to.path === '/login') {
      Router.push('/');
    } else {
      next();
    }
  } else {
    var whiteArr = ['/login', '/404', '/register'];
    const res = whiteArr.indexOf(to.path);
    if (res !== -1) {
      next();
    } else {
      Message.warning('未登录');
      next('/login');
    }
  }
});
